# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# email:  iroan@qq.com 
# date:   2018/1/23

'''
Usage:

Options:
    -h --help show this

Example:

'''

## 测试UDP
# 收数据，然后打印
# 检测键盘，然后发送
from socket import *
from threading import Thread


def recvData():
    while True:
        recvInfo = udp.recvfrom(1024)
        print('>>%s:%s' % (recvInfo[1]), bytes.decode(str))

def sendData():
    while True:
        sendInfo = input('<<')
        udp.sendto(sendInfo, ('192.168.0.114', 8081))

udp = None
# ip = ''
# port = 0

def main():
    global udp #不修改全局变量不用global关键字

    udp = socket(AF_INET, SOCK_DGRAM)
    udp.bind(('', 14567))

    tr = Thread(target=recvData) # 传递的是函数对象，不是调用函数
    ts = Thread(target=sendData)

    tr.start()
    ts.start()

    tr.join()
    ts.join()

if __name__ == '__main__':
    main()
